package com.qk.mangement.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Course;
import com.qk.entity.CourseQueryListByPageDto;
import com.qk.mangement.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Date:2025/10/13
 * Author:zxc
 * Description
 */
@RestController
@RequestMapping("/courses")
@Slf4j
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping
    public Result queryListByPage(CourseQueryListByPageDto courseQueryListByPageDto) {
        log.info("分页查询参数：{}", courseQueryListByPageDto);
        PageResult<Course> queryListByPageVO = courseService.queryListByPage(courseQueryListByPageDto);
        return Result.success(queryListByPageVO);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        log.info("删除参数：{}", id);
        courseService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result addCourse(@RequestBody Course course) {
        log.info("新增参数：{}", course);
        courseService.addCourse(course);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id) {
        log.info("查询参数：{}", id);
        Course course = courseService.queryById(id);
        return Result.success(course);
    }

    @PutMapping
    public Result updateById(@RequestBody Course course) {
        log.info("修改参数：{}", course);
        courseService.updateById(course);
        return Result.success();
    }

    @GetMapping("/list")
    public Result queryAll() {
        log.info("查询所有课程信息");
        return  Result.success(courseService.queryAll());
    }

    @GetMapping("/subject/{subject}")
    public Result queryBySubject(@PathVariable Integer subject){
        log.info("查询参数：{}", subject);
        return Result.success(courseService.queryBySubject(subject));
    }
}
